import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Header from '@/views/trainning/components/header'
import Opheader from '@/views/operation/components/opheader'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login1'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    component: () => import('@/views/index/index'),
    hidden: true
  },
  {
    path: '/trainning',
    component: Header,
    hidden: true, // 表示不显示左边导航栏
    children: [
      {
        path: 'index',
        component: () => import('@/views/trainning/index/index'),
        meta: { title: '实训管理首页' }
      },
      {
        path: 'cropdetail/:cropId',
        component: () => import('@/views/trainning/cropdetail/cropdetail'),
        meta: { title: '作物详情' }
      },
      {
        path: 'classdata/:cropId/:classId',
        component: () => import('@/views/trainning/classdata/classdata'),
        meta: { title: '班级数据' }
      },
      {
        path: 'persondata/:cropId/:studentId',
        component: () => import('@/views/trainning/persondata/persondata'),
        meta: { title: '个人数据' }
      },
      {
        path: 'persondatadetail/:dataReportId/:studentName',
        component: () => import('@/views/trainning/persondatadetail/persondatadetail'),
        meta: { title: '个人数据详情' }
      },
      {
        path: 'adddata/:cropId',
        component: () => import('@/views/trainning/adddata/adddata'),
        meta: { title: '增加数据' }
      },
      {
        path: 'updatedata',
        component: () => import('@/views/trainning/updatedata/updatedata'),
        meta: { title: '编辑数据' }
      },
      {
        path: 'statistic/:ids',
        component: () => import('@/views/trainning/statistic/statistic'),
        meta: { title: '统计分析' }
      },
      {
        path: 'index/manage',
        component: () => import('@/views/trainning/index/manage/manage'),
        meta: { title: '管理措施' }
      },
      {
        path: 'index/manage/list/:classId',
        component: () => import('@/views/trainning/index/manage/list'),
        meta: { title: '表单' }
      },
      {
        path: 'index/manage/list/detail/:studentId',
        component: () => import('@/views/trainning/index/manage/detail'),
        meta: { title: '实训措施管理' }
      },
      {
        path: 'studentManage',
        component: () => import('@/views/trainning/index/manage/stdManage'),
        meta: { title: '学生管理措施' }
      },
      {
        path: 'studentReport/:cropId',
        component: () => import('@/views/trainning/stdReport/index'),
        meta: { title: '学生实训报告列表' }
      },
      {
        path: 'teacherReport/:cropId/:studentId',
        component: () => import('@/views/trainning/managereport/teacherIndex'),
        meta: { title: '班级所有学生实训报告列表' }
      },
      {
        path: 'lookReport/:trainingReportId',
        component: () => import('@/views/trainning/stdReport/lookReport'),
        meta: { title: '学生实训报告' }
      },
      {
        path: 'correctReport/:trainingReportId',
        component: () => import('@/views/trainning/managereport/managereport'),
        meta: { title: '学生实训报告' }
      }
    ]
  },
  {
    path: '/operation',
    component: Opheader,
    hidden: true, // 表示不显示左边导航栏
    children: [
      {
        path: 'index',
        component: () => import('@/views/operation/index'),
        meta: { title: '物联网首页' }
      },
      {
        path: 'oxyWatch',
        component: () => import('@/views/operation/oxyWatch'),
        meta: { title: '物联网-养分监测' }
      },
      {
        path: 'artIrrigate',
        component: () => import('@/views/operation/artIrrigate'),
        meta: { title: '物联网-智能灌溉' }
      },
      {
        path: 'fieldWatch',
        component: () => import('@/views/operation/hkv'),
        meta: { title: '物联网-田间监测' }
      },
      {
        path: 'atmWatch',
        component: () => import('@/views/operation/atmWatch'),
        meta: { title: '物联网-气象监测' }
      }
    ]
  },
  {
    path: '/atmWatch/history/:RegionName',
    hidden: true,
    component: () => import('@/views/operation/history'),
    meta: { title: '气象监测-历史' }
  },
  {
    path: '/setting/index',
    component: Layout,
    name: 'schoolManagement',
    meta: {
      title: '学校管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'schoolSetting',
        component: () => import('@/views/schoolManagement/schoolSetting'),
        name: 'setup',
        meta: {
          title: '学校设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'baseSetting',
        component: () => import('@/views/schoolManagement/baseSetting'),
        name: 'setup',
        meta: {
          title: '基地设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'regionSetting',
        component: () => import('@/views/schoolManagement/regionSetting'),
        name: 'setup',
        meta: {
          title: '区域设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'aeraName',
        component: () => import('@/views/schoolManagement/aeraName'),
        name: 'name',
        meta: {
          title: '区域名称',
          icon: 'el-icon-s-help'
        }
      }
    ]
  },
  {
    path: '/setting/index/1',
    component: Layout,
    name: 'deviceManagement',
    meta: {
      title: '设备管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'typeManagement',
        component: () => import('@/views/deviceManagement/typeManagement'),
        name: 'setup',
        meta: {
          title: '类型设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'sensorManagement',
        component: () => import('@/views/deviceManagement/sensorManagement'),
        name: 'setup',
        meta: {
          title: '传感器设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'mutualManagement',
        component: () => import('@/views/deviceManagement/mutualManagement'),
        name: 'setup',
        meta: {
          title: '控制交互设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'monitorManagement',
        component: () => import('@/views/deviceManagement/monitorManagement'),
        name: 'setup',
        meta: {
          title: '视频监控设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'weatherManagement',
        component: () => import('@/views/deviceManagement/weatherManagement'),
        name: 'setup',
        meta: {
          title: '气象站设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'alertManagement',
        component: () => import('@/views/deviceManagement/alertManagement'),
        name: 'setup',
        meta: {
          title: '预警管理',
          icon: 'el-icon-s-help'
        }

      },
      {
        path: 'alertadd',
        component: () => import('@/views/deviceManagement/alertadd'),
        name: 'alert-add',
        meta: {
          title: '预警添加'
        },
        hidden: true

      },
      {
        path: ':warningName/:solutionContent/:earlyWarningId/alertupdate',
        component: () => import('@/views/deviceManagement/alertupdate'),
        name: 'alert-update',
        meta: {
          title: '预警修改'
        },
        hidden: true

      },
      {
        path: 'gatewaySetting',
        component: () => import('@/views/deviceManagement/gatewaySetting'),
        name: 'setup',
        meta: {
          title: '网关设置',
          icon: 'el-icon-s-help'
        }
      }

    ]
  },
  {
    path: '/setting/index/2',
    component: Layout,
    name: 'pestSetting',
    meta: {
      title: '病虫害管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'Insect',
        component: () => import('@/views/pestSetting/Insect'),
        name: 'setup',
        meta: {
          title: '百科',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'InsectType',
        component: () => import('@/views/pestSetting/InsectType'),
        name: 'setup',
        meta: {
          title: '百科分类',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'botanyType/:wikiCategoryName/:wikiCategoryId',
        component: () => import('@/views/pestSetting/botanyType'),
        name: 'setup',
        meta: {
          title: '植物分类',
          icon: 'el-icon-s-help'
        },
        hidden: true
      }

    ]
  },
  {
    path: '/setting/index/3',
    component: Layout,
    name: 'trainManagement',
    meta: {
      title: '实训管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'landManagement',
        component: () => import('@/views/trainManagement/landManagement'),
        name: 'setup',
        meta: {
          title: '地块管理',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'cropManagement',
        component: () => import('@/views/trainManagement/cropManagement'),
        name: 'setup',
        meta: {
          title: '作物管理',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'cropSetting/:cropId',
        component: () => import('@/views/trainManagement/cropSetting'),
        name: 'setup',
        meta: {
          title: '作物详情'
        },
        hidden: true
      },
      {
        path: 'measureManagement',
        component: () => import('@/views/trainManagement/measureManagement'),
        name: 'setup',
        meta: {
          title: '措施管理',
          icon: 'el-icon-s-help'
        }
      }
    ]
  },
  {
    path: '/setting/index/4',
    component: Layout,
    name: 'knowledgeManagement',
    meta: {
      title: '知识库管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'zhishiku',
        component: () => import('@/views/knowledgeManagement/zhishiku'),
        name: 'setup',
        meta: {
          title: '知识库管理',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'fenlei',
        component: () => import('@/views/knowledgeManagement/fenlei'),
        name: 'setup',
        meta: {
          title: '分类设置',
          icon: 'el-icon-s-help'
        }
      }
    ]
  },
  {
    path: '/setting/index/5',
    component: Layout,
    name: 'systemManagement',
    meta: {
      title: '系统管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'userManagement',
        component: () => import('@/views/systemManagement/userManagement'),
        name: 'setup',
        meta: {
          title: '用户设置',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'teacherManagement',
        component: () => import('@/views/systemManagement/teacherManagement'),
        name: 'setup',
        meta: {
          title: '教师设置',
          icon: 'el-icon-s-help'
        },
        hidden: true
      },
      {
        path: 'gradeManagement',
        component: () => import('@/views/systemManagement/gradeManagement'),
        name: 'setup',
        meta: {
          title: '年级管理',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'classManagement',
        component: () => import('@/views/systemManagement/classManagement'),
        name: 'setup',
        meta: {
          title: '班级管理',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'classSetting',
        component: () => import('@/views/systemManagement/classSetting'),
        name: 'setup',
        meta: {
          title: '班级设置',
          icon: 'el-icon-s-help'
        }

      },
      {
        path: 'classTeacher',
        component: () => import('@/views/systemManagement/classTeacheradd'),
        name: 'setup',
        meta: {
          title: '班师添加',
          icon: 'el-icon-s-help'
        },
        hidden: true
      },

      {
        path: 'limitManagement',
        component: () => import('@/views/systemManagement/limitManagement'),
        name: 'setup',
        meta: {
          title: '权限管理',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'journalManagement',
        component: () => import('@/views/systemManagement/journalManagement'),
        name: 'setup',
        meta: {
          title: '日志管理',
          icon: 'el-icon-s-help'
        }
      },
      {
        path: 'videoManagement',
        component: () => import('@/views/systemManagement/videoManagement'),
        name: 'setup',
        meta: {
          title: '视频截图',
          icon: 'el-icon-s-help'
        }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
